package com.baijiayun.liveuibase.toolbox.bonuspoints

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.baijiayun.liveuibase.R
import com.baijiayun.liveuibase.utils.BaseUIUtils
import com.baijiayun.liveuibase.utils.DisplayUtils
import com.baijiayun.liveuibase.utils.ThemeDataUtil
import com.baijiayun.liveuibase.utils.drawable.DrawableBuilder
import com.baijiayun.liveuibase.widgets.popupwindow.BaseAutoArrangePopupWindow

/**
 * Created by pengwenjian on 2021/7/30
 * Describe:
 */
@SuppressLint("SetTextI18n")
class BonusPointsPopupWindow(context: Context, val count:Int) : BaseAutoArrangePopupWindow(context) {
    var clickListener: View.OnClickListener? = null
    var selfWidth:Int = 0
    var selfHeight:Int = 0

    init {
        setDirectionMode(HORIZONTAL)
        val view = View.inflate(context, R.layout.uibase_layout_bonus_points_popup, null)
        view.background = DrawableBuilder()
            .cornerRadius(DisplayUtils.dip2px(context,8f))
            .strokeColor(ContextCompat.getColor(context, R.color.base_bg_stroke_10))
            .strokeWidth(1)
            .solidColor(
                ThemeDataUtil.getColorFromThemeConfigByAttrId(
                    context,
                    R.attr.base_theme_brand_container_color
                )
            )
            .build()
        view.findViewById<TextView>(R.id.bonus_points_add_tv).text = "+$count"
        view.setOnClickListener {
            clickListener?.onClick(it)
        }
        BaseUIUtils.setRoundCorner(
            view,
            DisplayUtils.dip2px(context,8f).toFloat()
        )
        createView(view, false)
        selfWidth = view.measuredWidth
        selfHeight = view.measuredHeight
    }

    override fun initViewDataHashMap() {
        // do nothing
    }

    override fun show(anchor: View) {
        isFocusable = true
        isOutsideTouchable = true
        initCustomOffset(-60 + DisplayUtils.px2dip(context, anchor.width * 0.5f), -10)
        showWithViewOfDirection(anchor, LEFT_TOP)
    }
}